// ============================================================================
//
// Copyright (C) 2006-2007 Dengues
//
// Google Group: http://groups.google.com/group/dengues
//
// QQ Group: 24885404
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// ============================================================================
package org.dengues.warehouse.viewers.action;

import java.util.ArrayList;

import org.dengues.core.actions.AbstractAction;
import org.dengues.core.warehouse.ENavNodeType;
import org.dengues.core.warehouse.ENodeCategoryName;
import org.dengues.core.warehouse.IWarehouseNode;
import org.dengues.warehouse.models.WarehouseNode;
import org.dengues.warehouse.viewers.WarehouseViewProvider;
import org.eclipse.ui.cheatsheets.ICheatSheetManager;

/**
 * Qiang.Zhang.Adolf@gmail.com class global comment. Detailled comment <br/>
 * 
 * $Id: Dengues.epf Qiang.Zhang.Adolf@gmail.com 2008-7-3 qiang.zhang $
 * 
 */
public abstract class CreateElementAction extends AbstractAction {

    /**
     * Qiang.Zhang.Adolf@gmail.com CreateMetaSourceAction constructor comment.
     */
    public CreateElementAction() {
        super();
    }

    /**
     * Qiang.Zhang.Adolf@gmail.com CreateMetaSourceAction constructor comment.
     * 
     * @param name
     */
    public CreateElementAction(String name) {
        super(name);
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.core.actions.AbstractAction#computeEnable()
     */
    @Override
    protected boolean computeEnable() {
        boolean isEnable = false;
        if (pnodes != null && pnodes.size() == 1) {
            isEnable = getNodeCategory() == pnodes.get(0).getCategoryName()
                    && ENavNodeType.ELEMENT != pnodes.get(0).getNodeType();
        }
        return isEnable;
    }

    /**
     * Qiang.Zhang.Adolf@gmail.com Comment method "getNodeCategory".
     * 
     * @return
     */
    protected abstract ENodeCategoryName getNodeCategory();

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.core.actions.AbstractAction#run(java.lang.String[],
     * org.eclipse.ui.cheatsheets.ICheatSheetManager)
     */
    @Override
    public void run(String[] params, ICheatSheetManager manager) {
        WarehouseNode dbNode = null;
        switch (getNodeCategory()) {
        case DATABASE:
        case QUERY:
            dbNode = WarehouseViewProvider.getDbNode();
            break;
        case PROCESS:
            dbNode = WarehouseViewProvider.getProcessNode();
            break;
        case XMLFILE:
            dbNode = WarehouseViewProvider.getXmlFileNode();
            break;
        case CSVFILE:
            dbNode = WarehouseViewProvider.getFlatFileNode();
            break;
        case EXCELFILE:
            dbNode = WarehouseViewProvider.getExcelFileNode();
            break;
        default:
            break;
        }
        pnodes = new ArrayList<IWarehouseNode>();
        pnodes.add(dbNode);
        run();
    }
}
